|
|
 |
|
|
|
|
' Find the desired center point. x1 = xmid
y1 = ymid
' Subtract half the height and width of the text
' bounding box. This puts (x1, y2) in the upper
' left corner of the text bounding box. x1 = x1 - text_bound_wid / 2
y1 = y1 - text_bound_hgt / 2
' The start position's X coordinate belongs at
' the left edge of the text bounding box, so
' x1 is correct. Move the Y coordinate down to
' its start position. y1 = y1 + text_wid * Sin(theta)
' Move (x1, y1) to the start corner of the
' outer bounding box. x1 = x1 - (total_bound_wid - text_bound_wid)
y1 = y1 - (total_bound_hgt - text_bound_hgt)
' Display the text. pic.CurrentX = x1
pic.CurrentY = y1
pic.Print txt : |
|
|
|
|
|
|
|
|
The previous sections explain how you can display text in different colors, sizes, and styles, giving you the equivalent of a multifont label. Unfortunately, the user cannot easily interact with this text, so you cannot use these techniques to make multifont text boxes. You could write a complex set of event handlers to allow the user to change the text, but this would be much more difficult than using a text box. |
|
|
|
|
|
|
|
|
Recent versions of Visual Basic come with the RichTextBox control. This control is similar to a text box, but it is much more powerful. A rich text box can display text using multiple colors, fonts, point sizes, and styles. It also includes a collection of useful text-processing features that allow paragraph alignment, indentation, hanging indentation, bullets, and so forth. |
|
|
|
|
|
|
|
|
To change the formatting of text in a rich text box, the text must first be selected. The user can select text as usual by clicking and dragging over the text. Programmatically, you can select text by setting the SelStart and SelLength properties to indicate where the selected text begins and how long it is. |
|
|
|
|
|
|
|
|
Once text is selected, you can use the rich text box's other properties to modify it. For example, you could use the following code to make the first 10 characters in a rich text box named rchStatements turn bold. |
|
|
|
|
|